←Select platform

WriteTransformMarker(int,byte[],int,int) Method

Summary
Controls how the transform markers are used when performing a lossless transformation for certain formats.
Syntax
C#
C++/CLI
Java
Python
public void WriteTransformMarker( 
   int id, 
   byte[] data, 
   int dataOffset, 
   int dataLength 
) 
public void writeTransformMarker(int id, byte data[], int dataOffset, int dataLength) 
public: 
void WriteTransformMarker(  
   int id, 
   array<byte>^ data, 
   int dataOffset, 
   int dataLength 
)  
def WriteTransformMarker(self,id,data,dataOffset,dataLength): 

Parameters

id
The id of the metadata marker.

data
A byte array containing the data for the metadata marker.

dataOffset
Offset into  data into which to begin the read operation.

dataLength
Number of bytes to read from  data.

Remarks

You should use this method to write a certain marker data into the file.

This method can be called only from within the CodecsTransformMarkerCallback passed to the Transform method.

The transform mechanism is as follows:

  • You call Transform.
  • Transform will call the CodecsTransformMarkerCallback callback passed to it for every marker contained in the source file. In the callback, you can replace markers, insert markers or allow LEADTOOLS to do the default processing (recommended).
  • You can override the default action for a marker by returning one of the following values from the transform callback:
    • CodecsTransformMarkerAction.Default: Let LEADTOOLS perform the default action on the marker. This means the marker might (or might not) be transformed and will be written to the destination file.
    • CodecsTransformMarkerAction.Ignore: This marker will be ignored (this is useful for stripping unwanted markers). You should also use this if you want to do your own transformation and write the marker yourself by calling WriteTransformMarker.
    • CodecsTransformMarkerAction.Abort: Abort the process. This will cause Transform to throw a 'user-abort' exception.

Note: You can also use WriteTransformMarker to insert your own markers. The marker will be inserted before the current marker. You can call WriteTransformMarker as many times as you wish. Every call to WriteTransformMarker will insert a new marker.

Warning: Incorrect handling of the markers will generate corrupt files! Since some markers contain important information about the image (image width, height, compression method, colorspace, etc), you should use caution when working with markers.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
 
 
public void TransformExample() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"); 
 
   string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_Transform.cmp"); 
 
 
   // Load the source image with markers 
   Debug.WriteLine("Loading the source image with all markers"); 
   codecs.Options.Load.Markers = true; 
   RasterImage srcImage = codecs.Load(srcFileName); 
 
   // Show the markers loaded, if any 
   Debug.WriteLine("These markers were loaded:"); 
   foreach (RasterMarkerMetadata marker in srcImage.Markers) 
   { 
      byte[] data = marker.GetData(); 
      codecs.WriteMarker(srcFileName, 1, marker); 
      // codecs.WriteMarker(stream, 1, marker); 
      codecs.WriteTransformMarker(marker.Id, data, 0, 1); 
      Debug.WriteLine(" {0}, DataSize:{1}", marker.Id, data.Length); 
   } 
 
   codecs.Transform( 
      srcFileName, 
      destFileName, 
      CodecsTransformFlags.Rotate90, 
      1, 
      CodecsTransformMarkerCallback); 
 
   // Clean up 
   codecs.Dispose(); 
} 
 
CodecsTransformMarkerAction CodecsTransformMarkerCallback(int id, RasterNativeBuffer buffer, CodecsTransformFlags transform) 
{ 
   Debug.WriteLine("Transforming: id: {0}, Data Length: {1}, transform: {2}", id, buffer.Length, transform); 
   return CodecsTransformMarkerAction.Default; 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 22.0.2023.5.5
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Codecs Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.